package com.egide.networks;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.IntentFilter;
import android.net.wifi.WifiManager;
import android.net.wifi.p2p.WifiP2pManager;
import android.net.wifi.p2p.WifiP2pManager.Channel;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.TextView;

import com.egide.R;

public class WiFiDirectActivity extends Activity {
//	private WifiManager wifi;
//	private TextView textStatus;
	BroadcastReceiver receiver;
	public static final String TAG = "WiFiDemo";
	
	private final IntentFilter intentFilter = new IntentFilter();
	private Channel mChannel;
	private WifiP2pManager mManager ;
	private boolean isWifiP2pEnabled = false;
	
		public void setIsWifiP2pEnabled(boolean isWifiP2pEnabled) {
			this.isWifiP2pEnabled = isWifiP2pEnabled;
		}
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_search_networks);
	
	    //  Indicates a change in the Wi-Fi Peer-to-Peer status.
	    intentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION);

	    // Indicates a change in the list of available peers.
	    intentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION);

	    // Indicates the state of Wi-Fi P2P connectivity has changed.
	    intentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);

	    // Indicates this device's details have changed.
	    intentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION);
	    
	    mManager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
	    mChannel = mManager.initialize(this, getMainLooper(), null);
	    
	    
		
	}
	   /** register the BroadcastReceiver with the intent values to be matched */
	 @Override
	 public void onResume() {
	     super.onResume();
	     receiver = new WifiDirectBroadcastReceiver(mManager, mChannel, this);
	     registerReceiver(receiver, intentFilter);
	 }
	
	 @Override
	 public void onPause() {
	     super.onPause();
	     unregisterReceiver(receiver);
	 }
	
	public void search_networks(View view){
		//Intent intent = new Intent(this,Search_Networks_Activity.class);
	//	wifi.startScan();
	//	startActivity(intent);
	}
	


	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_search_networks, menu);
		return true;
	}

}
